//
//  DHSubscribe_CompensationController.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/6/14.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHSubscribe_CompensationController.h"
#import "DHPayViewController.h"

@interface DHSubscribe_CompensationController ()

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UIButton *payButton;

@property (strong, nonatomic) NSDictionary *dic;

@end

@implementation DHSubscribe_CompensationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleLabel.text = @"赔偿信息";
    
    self.payButton.layer.cornerRadius = self.payButton.height / 2;
    
    [[DHNetAPIClient shareDHNetAPIClient] request_order_compensateWithParams:@{@"size_id":self.size_id} andBlock:^(id data, NSError *error) {
        self.dic = [data objectForKey:@"compensate"];
        
        self.priceLabel.text = [NSString stringWithFormat:@"￥%.2f",[[self.dic objectForKey:@"fee"] floatValue]];
        self.textView.text = [self.dic objectForKey:@"reason"];
        
        NSArray *images = [self.dic objectForKey:@"images"];
        [images enumerateObjectsUsingBlock:^(NSString *url, NSUInteger idx, BOOL * _Nonnull stop) {
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((5 + 60) * idx, 0, 60, self.scrollView.height)];
            [imageView dh_setImageURLString:url];
            [self.scrollView addSubview:imageView];
        }];
    }];
    
    WeakSelf(weakSelf)
    [self.payButton bk_addEventHandler:^(id sender) {
        float price = [[weakSelf.dic  objectForKey:@"fee"] floatValue];
        DHPayViewController *vc = [[DHPayViewController alloc] initWithPrice:@(price) order_id:[weakSelf.dic objectForKey:@"_id"]];
        vc.payType = PayTypeCompensate;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    } forControlEvents:UIControlEventTouchUpInside];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
